
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>国际化 · introduce</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gj">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../index.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="eslint.html" />
    
    
    <link rel="prev" href="icons.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="vscode.html">
            
                <a href="vscode.html">
            
                    
                    Vscode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="jsdoc.html">
            
                <a href="jsdoc.html">
            
                    
                    Jsdoc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="webpack.html">
            
                <a href="webpack.html">
            
                    
                    Webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="router.html">
            
                <a href="router.html">
            
                    
                    路由和侧边栏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="cors.html">
            
                <a href="cors.html">
            
                    
                    跨域问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="router-lazyload.html">
            
                <a href="router-lazyload.html">
            
                    
                    路由懒加载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="icons.html">
            
                <a href="icons.html">
            
                    
                    图标
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.10" data-path="i18n.html">
            
                <a href="i18n.html">
            
                    
                    国际化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="eslint.html">
            
                <a href="eslint.html">
            
                    
                    ESLint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="permission.html">
            
                <a href="permission.html">
            
                    
                    权限验证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="style.html">
            
                <a href="style.html">
            
                    
                    样式
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >国际化</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x56FD;&#x9645;&#x5316;">&#x56FD;&#x9645;&#x5316;</h1>
<p>&#x672C;&#x9879;&#x76EE;&#x96C6;&#x5408;&#x4E86;&#x56FD;&#x9645;&#x5316; i18n &#x65B9;&#x6848;&#x3002;&#x901A;&#x8FC7; <a href="https://github.com/kazupon/vue-i18n" target="_blank">vue-i18n</a>&#x800C;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x672C;&#x9879;&#x76EE; ui &#x6846;&#x67B6;&#x4F7F;&#x7528;&#x4E86;<code>element</code>&#xFF0C;&#x6240;&#x4EE5;&#x56FD;&#x9645;&#x5316;&#x7684;&#x540C;&#x65F6;&#x4E5F;&#x8981;&#x5C06;&#x5176;&#x56FD;&#x9645;&#x5316;&#x3002; <a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/src/lang/index.js" target="_blank">&#x5B8C;&#x6574;&#x4EE3;&#x7801;</a>&#x3002; &#x540C;&#x65F6;&#x5C06;&#x5F53;&#x524D; <code>lang</code> &#x8BED;&#x8A00;&#x5B58;&#x5728; <code>cookie</code>&#x4E4B;&#x4E2D;&#xFF0C;&#x4E3A;&#x4E86;&#x4E0B;&#x6B21;&#x6253;&#x5F00;&#x9875;&#x9762;&#x80FD;&#x8BB0;&#x4F4F;&#x4E0A;&#x6B21;&#x7684;&#x8BED;&#x8A00;&#x8BBE;&#x7F6E;&#x3002;</p>
<h1 id="&#x5168;&#x5C40;-lang">&#x5168;&#x5C40; lang</h1>
<p>&#x4EE3;&#x7801;&#x5730;&#x5740;: <a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/lang" target="_blank">@/lang</a> &#x76EE;&#x524D;&#x914D;&#x7F6E;&#x4E86;&#x82F1;&#x6587;&#x548C;&#x4E2D;&#x6587;&#x4E24;&#x79CD;&#x8BED;&#x8A00;&#x3002;</p>
<p>&#x540C;&#x65F6;&#x5728; <code>@/lang/index.js</code> &#x4E2D;&#x5F15;&#x5165;&#x4E86; <code>element-ui</code>&#x7684;&#x8BED;&#x8A00;&#x5305;</p>
<p><strong>&#x4F7F;&#x7528;&#xFF1A;</strong></p>
<pre class="language-"><code class="lang-js"><span class="token comment">// $t &#x662F; vue-i18n &#x63D0;&#x4F9B;&#x7684;&#x5168;&#x5C40;&#x65B9;&#x6CD5;&#xFF0C;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#x8BF7;&#x67E5;&#x770B;&#x5176;&#x6587;&#x6863;</span>
<span class="token function">$t</span><span class="token punctuation">(</span><span class="token string">&apos;login.title&apos;</span><span class="token punctuation">)</span>
</code></pre>
<h1 id="&#x5F02;&#x6B65;-lang">&#x5F02;&#x6B65; lang</h1>
<p>&#x6709;&#x4E00;&#x4E9B;&#x67D0;&#x4E9B;&#x7279;&#x5B9A;&#x9875;&#x9762;&#x624D;&#x9700;&#x8981;&#x7684; lang&#xFF0C;&#x6BD4;&#x5982; <code>@/views/i18n-demo</code> &#x9875;&#x9762;</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">import</span> local <span class="token keyword">from</span> <span class="token string">&apos;./local&apos;</span>

<span class="token keyword">this</span><span class="token punctuation">.</span>$i18n<span class="token punctuation">.</span><span class="token function">mergeLocaleMessage</span><span class="token punctuation">(</span><span class="token string">&apos;en&apos;</span><span class="token punctuation">,</span> local<span class="token punctuation">.</span>en<span class="token punctuation">)</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>$i18n<span class="token punctuation">.</span><span class="token function">mergeLocaleMessage</span><span class="token punctuation">(</span><span class="token string">&apos;zh&apos;</span><span class="token punctuation">,</span> local<span class="token punctuation">.</span>zh<span class="token punctuation">)</span>
</code></pre>
<h1 id="js-&#x4E2D;&#x4F7F;&#x7528;-t">js &#x4E2D;&#x4F7F;&#x7528; $t</h1>
<p>&#x5982;&#x679C;&#x4F60;&#x4F7F;&#x7528;&#x5982; <code>select</code>&#x7EC4;&#x4EF6;&#xFF0C;&#x5B83;&#x7684;&#x503C;&#x662F;&#x901A;&#x8FC7; <code>v-for</code>&#x800C;&#x6765;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-select</span> <span class="token attr-name">v-model</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>value<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-option</span>
    <span class="token attr-name">v-for</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>item in options<span class="token punctuation">&quot;</span></span>
    <span class="token attr-name">:key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>item.value<span class="token punctuation">&quot;</span></span>
    <span class="token attr-name">:label</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>item.label<span class="token punctuation">&quot;</span></span>
    <span class="token attr-name">:value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>item.value<span class="token punctuation">&quot;</span></span><span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-select</span><span class="token punctuation">&gt;</span></span>
this.options = [
  {
    value: &apos;1&apos;,
    label: this.$t(&apos;i18nView.one&apos;)
  },
  {
    value: &apos;2&apos;,
    label: this.$t(&apos;i18nView.two&apos;)
  },
  {
    value: &apos;3&apos;,
    label: this.$t(&apos;i18nView.three&apos;)
  }
]
</code></pre>
<p>&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x56FD;&#x9645;&#x5316;&#x53EA;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x56E0;&#x4E3A;&#x5728; js &#x4E2D;&#x7684;<code>this.options</code>&#x53EA;&#x4F1A;&#x5728;&#x521D;&#x59CB;&#x5316;&#x7684;&#x65F6;&#x5019;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x5B83;&#x7684;&#x6570;&#x636E;&#x5E76;&#x4E0D;&#x4F1A;&#x968F;&#x7740;&#x4F60;&#x672C;&#x5730; <code>lang</code>&#x7684;&#x53D8;&#x5316;&#x800C;&#x53D8;&#x5316;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x4F60;&#x5728;<code>lang</code>&#x53D8;&#x5316;&#x7684;&#x65F6;&#x5019;&#x624B;&#x52A8;&#x91CD;&#x8BBE;<code>this.options</code>&#x3002;</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  watch<span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token function">lang</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setOptions</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  methods<span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token function">setOptions</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>options <span class="token operator">=</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span>
          value<span class="token operator">:</span> <span class="token string">&apos;1&apos;</span><span class="token punctuation">,</span>
          label<span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$t</span><span class="token punctuation">(</span><span class="token string">&apos;i18nView.one&apos;</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token punctuation">{</span>
          value<span class="token operator">:</span> <span class="token string">&apos;2&apos;</span><span class="token punctuation">,</span>
          label<span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$t</span><span class="token punctuation">(</span><span class="token string">&apos;i18nView.two&apos;</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token punctuation">{</span>
          value<span class="token operator">:</span> <span class="token string">&apos;3&apos;</span><span class="token punctuation">,</span>
          label<span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$t</span><span class="token punctuation">(</span><span class="token string">&apos;i18nView.three&apos;</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h1 id="&#x79FB;&#x9664;&#x56FD;&#x9645;&#x5316;">&#x79FB;&#x9664;&#x56FD;&#x9645;&#x5316;</h1>
<p>&#x5728; <code>src/main.js</code> &#x4E2D;&#x79FB;&#x9664; <code>import i18n from &apos;./lang&apos;</code> &#x5E76;&#x4E14;&#x5220;&#x9664; <code>src/lang</code> &#x6587;&#x4EF6;&#x5939;&#x3002;</p>
<p>&#x5E76;&#x5728; <code>src/layout/components/Levelbar</code>&#x3001;<code>src/layout/components/SidebarItem</code>&#x3001;<code>src/layout/components/TabsView</code> &#x7B49;&#x6587;&#x4EF6;&#x5939;&#x4E2D; &#x79FB;&#x9664; <code>this.$t(&apos;route.xxxx&apos;)</code> &#x4F7F;&#x7528;&#x56FD;&#x9645;&#x5316;&#x7684;&#x65B9;&#x5F0F;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="icons.html" class="navigation navigation-prev " aria-label="Previous page: 图标">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="eslint.html" class="navigation navigation-next " aria-label="Next page: ESLint">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"国际化","level":"1.10","depth":1,"next":{"title":"ESLint","level":"1.11","depth":1,"path":"src/eslint.md","ref":"src/eslint.md","articles":[]},"previous":{"title":"图标","level":"1.9","depth":1,"path":"src/icons.md","ref":"src/icons.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","-lunr","-search","search-pro","-highlight","prism","livereload"],"styles":{"website":"index.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"expandable-chapters":{},"search-pro":{},"livereload":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Gj","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"introduce","language":"zh-hans","gitbook":"3.2.3","description":"项目搭建、规范、使用示例介绍"},"file":{"path":"src/i18n.md","mtime":"2020-07-29T03:15:32.767Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-07-29T07:02:36.580Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

